package com.xunqi.ad.controller;

import com.alibaba.fastjson.JSON;
import com.xunqi.ad.exception.AdException;
import com.xunqi.ad.form.*;
import com.xunqi.ad.service.IAdUnitService;
import com.xunqi.ad.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Description:
 * @Created with IntelliJ IDEA.
 * @author: 夏沫止水
 * @createTime: 2020-05-01 21:35
 **/
@Slf4j
@RestController
public class AdUnitOPController {

    @Resource
    private IAdUnitService adUnitService;

    @PostMapping(value = "/create/adUnit")
    public ResponseVo<AdUnitResponseVo> createUnit(@Valid @RequestBody AdUnitForm form) throws AdException {

        log.info("ad-sponsor: createUnit -> {}",
                JSON.toJSONString(form));

        ResponseVo<AdUnitResponseVo> unitResponseVo = adUnitService.createUnit(form);

        return unitResponseVo;
    }


    @PostMapping(value = "/create/unitKeyword")
    public ResponseVo<AdUnitKeywordResponseVo> createUnitKeyword(@Valid @RequestBody AdUnitKeywordForm form) throws AdException {

        log.info("ad-sponsor: createUnitKeyword -> {}",
                JSON.toJSONString(form));

        ResponseVo<AdUnitKeywordResponseVo> unitKeywordResponseVo = adUnitService.createUnitKeyword(form);

        return unitKeywordResponseVo;
    }

    @PostMapping(value = "/create/unitIt")
    public ResponseVo<AdUnitItResponseVo> createUnitIt(@Valid @RequestBody AdUnitItForm form) throws AdException {

        log.info("ad-sponsor: createUnitIt -> {}",
                JSON.toJSONString(form));

        ResponseVo<AdUnitItResponseVo> unitItResponseVo = adUnitService.createUnitIt(form);

        return unitItResponseVo;
    }


    @PostMapping(value = "/create/unitDistrict")
    ResponseVo<AdUnitDistrictResponseVo> createUnitDistrict(@Valid @RequestBody AdUnitDistrictForm form) throws AdException {

        log.info("ad-sponsor: createUnitDistrict -> {}",
                JSON.toJSONString(form));

        ResponseVo<AdUnitDistrictResponseVo> unitDistrictResponseVO = adUnitService.createUnitDistrict(form);

        return unitDistrictResponseVO;
    }

    @PostMapping(value = "/create/creativeUnit")
    public ResponseVo<CreativeUnitResponseVo> createCreativeUnit(@Valid @RequestBody CreativeUnitForm form) throws AdException {

        log.info("ad-sponsor: createCreativeUnit -> {}",
                JSON.toJSONString(form));

        ResponseVo<CreativeUnitResponseVo> creativeUnitResponseVo = adUnitService.createCreativeUnit(form);

        return creativeUnitResponseVo;
    }


}
